/***************************************************************************\
 * Copyright (C) by Keio University
 * Camera.hpp created in 09 2011.
 * Mail : fdesorbi@hvrl.ics.keio.ac.jp
 *
 * Camera.hpp is part of the HVRL Engine Library.
 *
 * The HVRL Engine Library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * The HVRL Engine Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 \***************************************************************************/

#ifndef __COMMON__LOGTOOLS_HPP__
#define __COMMON__LOGTOOLS_HPP__

#include <iostream>
#include <fstream>
#include <string>

namespace hvrl {

enum LogLevel {
	QUIET = 0,
	MODERATE,
	COMPLETE,
	COMPLETE_WITH_DEBUG,
	INFO,
	DEBUG_MODE,
	ERROR_MODE,
	WARNING_MODE
};

class Log {

private:

	Log(void) :
			fp_standard(&(std::cout)), fp_error(&(std::cerr)), level(MODERATE) {
	}

	~Log(void) {
	}

	Log(const Log&);
	Log& operator=(const Log&);

public:

	void setOutputError(std::ostream* fp) {
		if (fp)
			this->fp_error = fp;
	}

	void setOutputStandard(std::ostream* fp) {
		if (fp)
			this->fp_standard = fp;
	}

	void setOutput(std::ostream* fp) {
		if (fp) {
			this->fp_error = fp;
			this->fp_standard = fp;
		}
	}

	static inline Log &getInstance(void) {
		return log_singleton;
	}

	static inline Log &add(void) {
		return log_singleton;
	}

	void warning(const std::string& functionname, const std::string& message =
			"") {
		if (this->level == WARNING_MODE || this->level == COMPLETE
				|| this->level == COMPLETE_WITH_DEBUG) {
			*(this->fp_error) << "WARNING [" << functionname << "] : "
					<< message << "." << std::endl;
		}
	}

	void error(const std::string& functionname,
			const std::string& message = "") {
		if (this->level == ERROR_MODE || this->level == MODERATE
				|| this->level == COMPLETE
				|| this->level == COMPLETE_WITH_DEBUG) {
			*(this->fp_error) << "ERROR [" << functionname << "] : " << message
					<< "." << std::endl;
		}
	}

	void debug(const std::string& functionname,
			const std::string& message = "") {
		if (this->level == DEBUG_MODE || this->level == ERROR_MODE
				|| this->level == WARNING_MODE
				|| this->level == COMPLETE_WITH_DEBUG) {
			*(this->fp_error) << "DEBUG [" << functionname << "] : " << message
					<< "." << std::endl;
		}
	}

	void info(const std::string& message) {
		if (this->level == INFO || this->level == QUIET
				|| this->level == MODERATE || this->level == COMPLETE
				|| this->level == COMPLETE_WITH_DEBUG) {
			*(this->fp_standard) << "INFO : " << message << "." << std::endl;
		}
	}

	std::ostream& err(void) {
		return *(this->fp_error);
	}

	std::ostream& out(void) {
		return *(this->fp_standard);
	}

	enum LogLevel getLevel(void) const {
		return (this->level);
	}

	void setLevel(const enum LogLevel & level) {
		this->level = level;
	}

private:

	std::ostream* fp_standard;
	std::ostream* fp_error;
	enum LogLevel level;

	static Log log_singleton;

};

}

#endif
